package com.studyv3.framework.lock;

import org.redisson.api.RLock;

import java.util.concurrent.TimeUnit;

public class RedissonUtil {

    public static boolean tryLockNoThrow(RLock lock, long waitTime, long leaseTime, TimeUnit unit) {
        try {
            return lock.tryLock(waitTime, leaseTime, unit);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            return false;
        }
    }

    public static void unLockNoThrow(RLock lock) {
        if (!lock.isHeldByCurrentThread()) {
            return;
        }
        try {
            lock.unlock();
        } catch (Exception ex) {}
    }
}
